import java.util.Arrays;

/**
 * 省份数量
 * https://leetcode.cn/problems/number-of-provinces/solutions/
 *
 */

class Solution {
    public int findCircleNum(int[][] isConnected) {
        int n = isConnected.length;
        UnionFindSet ufs= new UnionFindSet(n);
        for(int i = 0; i < isConnected.length;i++) {
            for(int j = 0; j < isConnected[i].length;j++) {
                if(j != i && isConnected[i][j] == 1) {
                    ufs.union(i,j);
                }
            }
        }
        return ufs.getCount();
    }
}